import java.sql.*;

public class JdbcTest02 {
    public static void main(String[] args) {
        Connection cnn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;

        try {
            //注册驱动
            Class.forName("com.mysql.jdbc.Driver");
            //获取连接对象
            cnn = DriverManager.getConnection("jdbc:mysql://localhost:3306/hjy","root","123456");
            //创建数据库操作对象（statement,preparedStatement)
            //执行sql语句
            ps = cnn.prepareStatement("select *from emp where job = ?");
            ps.setString(1,"manager");
            rs = ps.executeQuery();
            //处理查询结果集
            while (rs.next()) {

                System.out.println(rs.getString("ename") + "," +
                        (rs.getDouble("sal") +200)+"," + rs.getString("job"));
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            //释放资源
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (ps != null) {
                try {
                    ps.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            } if (cnn != null) {
                try {
                    cnn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
